import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
    {
        path: '/',
        name: 'home',
        component: HomeView
    },
    {
        path: '/random-wheel',
        name: 'random-wheel',
        component: () => import('../views/WheelView.vue'),
        meta: { title:'选择困难症转盘',
            prColor: '#a78bfa',
            ttColor: '#a78bfa',
            bgColor: '#ffffff',
            hlColor: '#ffffff'
        }
    },
    {
        path: '/unit-converter',
        name: 'unit-converter',
        component: () => import('../views/UnitConverterView.vue'),
        meta: { title: '单位换算器',
            bg: '#c2ffc7',
            prColor: '#c2ffc7',
            ttColor: '#c2ffc7',
            bgColor: '#ffbece',
            hlColor: '#ffbece'
        }
    },
    {
        path: '/bmi',
        name: 'bmi',
        component: () => import('../views/BMIView.vue'),
        meta: { 
            title: 'BMI计算器',
            prColor: '#42b983',
            ttColor: '#42b983',
            bgColor: '#ffffff',
            hlColor: '#ffffff'
        }
    },
    {
        path: '/fortune',
        name: 'fortune',
        component: () => import('../views/FortuneView.vue'),
        meta: {
            title: '运势推送/电子上香',
            prColor: '#be4a18',
            ttColor: '#cc8a61',
            bgColor: '#f6dc99',
            hlColor: '#ffffff'
        },
        requiresAuth: false
    },
    {
        path: '/virtual-cat',
        name: 'virtual-cat',
        component: () => import('../views/VirtualCatView.vue'),
        meta: {
            title: '虚拟猫咪',
            prColor: '#be185d',
            ttColor: '#be185d',
            bgColor: '#f9a8d4',
            hlColor: '#ffffff'
        },
        requiresAuth: false
    },
    {
        path: '/morse',
        name: 'morse',
        component: () => import('../views/MorseCodeView.vue'),
        meta: { title: '摩斯密码转换器',
            prColor: '#AA0080',
            ttColor: '#B2C4FF',
            bgColor: '#000000',
            hlColor: '#ffffff'
        }
    }
]

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes
})


// 设置页面标题
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
        next()
    }
    else{next()}
})

export default router